package com.example.test.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @desc:随机生成工具类
 * @author:tangn
 * @date:2020/3/21
 * @time:22:28
 */
public class RandomUtils {

    /**
     * 随机生成位数
     */
    private final static Integer LIMIT_NUM = 3;
    private final static Integer LIMIT_THIRD_NUM = 5;
    /**
     * 密码长度
     */
    private final static Integer PASSWORD_LENGTH = 7;

    /**
     * 订单号生成器
     *
     * @return
     */
    public static String getOrderNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = sdf.format(new Date());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < LIMIT_NUM; i++) {
            result += random.nextInt(10);
        }
        return newDate + result;
    }

    /**
     * 订单号生成器
     *
     * @return
     */
    public static String getThirdNo() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String newDate = sdf.format(new Date());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < LIMIT_THIRD_NUM; i++) {
            result += random.nextInt(10);
        }
        return newDate + result;
    }

    /**
     * 获取用户唯一码
     *
     * @return
     */
    public static String getUnionCode() {
        return MD5Utils.getMD5(getOrderNo());
    }

    /**
     * 获取随机密码
     *
     * @return static
     */
    public static String getRandomPassword() {
        String result = "";
        Random random = new Random();
        for (int i = 0; i < PASSWORD_LENGTH; i++) {
            result += random.nextInt(10);
        }
        return result;
    }

}
